<?php
header("Content-type: text/html; charset=utf-8");
include_once('dependency/WxPayPubHelper/WxPayPubHelper.php');
define('IN_QY',true);
session_start();
require("include/common.inc.php");
require_once('config.php');


$sqla="select * from tbl_taospp where id=".$_GET['moneyid'];
$a=mysql_query($sqla);
$rowa=mysql_fetch_array($a);



setcookie("gswxfid",$rowa['zswprice'],time()+(3600*12*1*1));
setcookie("gswxfidd",$_GET['moneyid'],time()+(3600*12*1*1));

if($_COOKIE['openid']==""){
$jsApi = new JsApi_pub();
//网页授权获取用户openid
//通过code获得openid
$openid = "";
try {
    if (!isset($_GET['code'])) {
        //触发微信返回code码
        $url = $jsApi->createOauthUrlForCode("http://www.goodshare.com.cn/wap/cwvipwxlogin.php");
        Header("Location: $url");
    } else {
        //获取code码，以获取openid
        $code = $_GET['code'];
        $jsApi->setCode($code);
        $openid = $jsApi->getOpenId();
		setcookie("openid",$openid,time()+(3600*8*1*1),"/");  
    }
} catch (Exception $e) {
 echo $e->getMessage();
    exit();
}

} else{
	
$openid =$_COOKIE['openid'];	
}


if($_GET['moneyid']){
	
$money = $rowa['zswprice'];
$shopid = $_GET['moneyid'];	
}else
{
	
	
$money = $_COOKIE['gswxfid'];
	
$shopid = $_COOKIE['gswxfidd'];	
}	
	
//
	$sqlyy="select * from tbl_user where id=".$_COOKIE['userid'];
	$queryyy=mysql_query($sqlyy);
	$rowyy=mysql_fetch_array($queryyy);	

?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title><?=$_COOKIE['shuyu']?>/微信支付页面-众晒网</title>
    <link rel="stylesheet" type="text/css" href="/ui/css/Hui.css" />
    <style type="text/css">
         #header{width:100%; height:44px; position:absolute; top:0;}
         #footer{width:100%; height:55px; position:absolute; bottom:0;}	 
        #main{width:100%; overflow: auto; position:absolute; top:44px;bottom:0px;} 
    </style>
</head>
<body class="H-flexbox-vertical">
    <header class="H-header H-theme-background-color-white" id="header">
        <span tapmode="" class="H-icon H-position-relative H-display-inline-block H-float-left H-vertical-middle H-theme-font-color-white H-padding-horizontal-left-5 H-z-index-100" onclick="H.closeWin();"><i class="H-iconfont H-icon-arrow-left H-font-size-18 H-theme-font-color-black  H-vertical-middle"></i></span>
        <div class="H-header-title H-center-all H-font-size-18 H-text-show-row-1 H-theme-font-color-black H-position-absolute H-width-100-percent">
            微信支付中
        </div>
        <span tapmode="" class="H-icon H-position-relative H-display-inline-block H-float-right H-vertical-middle H-theme-font-color-white H-padding-horizontal-right-8 H-z-index-100" onclick="H.openWin('add_head','add_head.html')"></span>
    </header>
    <div id="main" >
     <!-- 充值余额 -->
       <div class="H-padding-vertical-bottom-10"></div>	 
	    <div  class="H-channel-title H-flexbox-horizontal H-theme-background-color-white H-vertical-middle H-border-vertical-bottom-after">
        <div class="H-channel-line H-theme-background-color8 H-padding-vertical-top-15 H-padding-horizontal-left-3  H-margin-horizontal-left-10"></div>
        <div class="H-channel-text H-theme-font-color9 H-flex-item H-font-size-18 H-theme-font-color-black H-padding-10 H-margin-horizontal-right-10 H-text-show-row-1">待支付:￥<?=$money?></div>
    </div>
	       <div class="H-padding-vertical-bottom-10"></div>	 
	    <div  class="H-channel-title H-flexbox-horizontal H-theme-background-color-white H-vertical-middle H-border-vertical-bottom-after">
        <div class="H-channel-line H-theme-background-color8 H-padding-vertical-top-15 H-padding-horizontal-left-3  H-margin-horizontal-left-10"></div>
        <div class="H-channel-text H-theme-font-color9 H-flex-item H-font-size-18 H-theme-font-color-black H-padding-10 H-margin-horizontal-right-10 H-text-show-row-1">商品ID：<?=$shopid?></div>
    </div>
        <div class="H-padding-vertical-bottom-10"></div>
        <button id="test" style="z-index:99999999999" class="H-button H-z-index-900 H-width-100-percent  H-font-size-15 H-outline-none H-theme-background-color-transparent H-padding-vertical-both-12 H-padding-horizontal-both-20 H-theme-font-color8 H-theme-border-color8 H-theme-border-color8-click H-theme-background-color8-click H-theme-font-color8-click H-border-radius-3">确认微信支付<span class="H-badge H-display-inline-block"></span></button>
        <div class="H-padding-vertical-bottom-10"></div>	
</div>
<script type="text/javascript" src="/ui/script/H.js"></script>
    <script type="text/javascript" src="/ui/xianzhi/js/jquery.min.js"></script>
    <script type="text/javascript" src="/ui/layer/mobile/layer.js"></script>  
<div id="qr"></div>
<script id='spay-script' src='https://jspay.beecloud.cn/1/pay/jsbutton/returnscripts?appId=92cebded-aa13-4ded-adc3-4870aa68ef90'></script>
<?php
if($_COOKIE['gswxfid']==""){	

 echo "<script>alert('请选择兑换方式');window.location.href='my.php';</script>";
}
$viptitle='尊享VIP付费';
$trade_no=time().rand(100,999);
$data = array(
    "app_id" =>  "92cebded-aa13-4ded-adc3-4870aa68ef90",
    "title" => $viptitle,
    "amount" => $money*100,
    "out_trade_no" => $trade_no,
    "openid" => $openid,
    "trace_id" => "zsw"
);
$app_secret = "320c075b-f5b2-49de-95a3-5b10f6119775";
$sign = md5($data['app_id'] . $data['title'] . $data['amount'] . $data['out_trade_no'] . $app_secret);
$data["sign"] = $sign;
$data["optional"] = json_decode(json_encode(array("hello" => "1")));
//    $data["openid"] ="o3kKrjlUsMnv__cK5DYZMl0JoAkY";   //o3kKrjlUsMnv__cK5DYZMl0JoAkY   oOCyauJ6nKcXiIIQ_bixiQpaL6PQ(me)
?>
<!--
<div><?php echo json_encode($data) ?></div>
-->
<script>
    document.getElementById("test").onclick = function() {
        asyncPay();
    };

    function bcPay() {
        BC.click(<?php echo json_encode($data) ?>, {
            wxJsapiFinish : function(res) {
                //jsapi接口调用完成后
				 if(res.err_msg == "get_brand_wcpay_request:cancel" ) {
					 
				 alert('您取消了支付');	 
				location.reload() ; 	 
				 }
				 if(res.err_msg == "get_brand_wcpay_request:ok" ) {
			 var pay_type='2';	 
			 var goodid = '<?=$money?>';
			 var uid= '<?=$_COOKIE['userid']?>';
			 var goodsid = '<?=$shopid?>';	

		$.ajax({
        url: './cwviphd.php',
        type: 'POST',
        dataType: 'json',
        data: {goodid: goodid,
		pay_type:pay_type,
		uid:uid
		
		},
      })
      .done(function(respon) {
		   
        if (respon.error==0) {
			
	    $.ajax({
        url: '/api/muyin/api.php?s=user.pay_vip_use_score',
        type: 'POST',
        dataType: 'json',
        data: {goodsid: goodsid,
		pay_type:pay_type,
		uid:uid
		
		},
      })	
		
		   .done(function(respon) {
		
		
	layer.open({
    content: '支付成功'
    ,btn: ['知道了']
    ,yes: function(index){
      window.location.href="my.php"; 
      layer.close(index);
    }
  });
		

		   
		

        })		
				
        }else{
             
        }
	
      }) 
	 
				 }
               
            }
        });
    }
    
    // 这里不直接调用BC.click的原因是防止用户点击过快，BC的JS还没加载完成就点击了支付按钮。
    // 实际使用过程中，如果用户不可能在页面加载过程中立刻点击支付按钮，就没有必要利用asyncPay的方式，而是可以直接调用BC.click。
    function asyncPay() {
        if (typeof BC == "undefined") {
            if (document.addEventListener) { // 大部分浏览器
                document.addEventListener('beecloud:onready', bcPay, false);
            } else if (document.attachEvent) { // 兼容IE 11之前的版本
                document.attachEvent('beecloud:onready', bcPay);
            }
        } else {
            bcPay();
        }
    }
</script>



</body>
</html>